<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page import="ws.SPWebService"%>
<%@ page import="ws.WebServiceBean"%>
<%@ page import="project.utils.Utils"%>
<%@ page import="project.utils.Parser"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.HashMap"%>
<% 
	SPWebService sp = new SPWebService();
	WebServiceBean ws = sp.getWebServiceBeanPort(); 
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Регистрация</title>
<style type="text/css">
body {background-image: url(images/Sport.jpg);background-repeat: repeat-y;}
body,td,th {color: #F60;text-align: center;}
a:link {color: #0F0;text-decoration: none;}
a:visited {color: #0F0;text-decoration: none;}
a:hover {text-decoration: none;color: #060;}
a:active {text-decoration: none;color: #F60;}
.green {color: #0F0;}
</style>
</head>
<body>
	<div align="center">
		<table width="864" border="1">
			<tr>
				<th width="758" height="185" bgcolor="#000000" scope="col"><h1>
						<strong class="В"><em>PLANET OF SPORT </em></strong><img
							src="images/Planet.jpg" width="260" height="208" alt="" />
					</h1></th>
			</tr>
			<tr>
				<td height="57" bgcolor="#000000"><div align="center">
						<h2 class="green">
							<big>РЕГИСТРАЦИЯ НОВОГО ПОЛЬЗОВАТЕЛЯ</big>
						</h2>
					</div></td>
			</tr>
			<tr>
				<td height="294" bgcolor="#000000">
					<%
						if (request.getParameter("registration") != null) {
							String[] dataUser = new String[10];
							dataUser[0] = request.getParameter("firstname");
							dataUser[1] = request.getParameter("lastname");
							dataUser[2] = request.getParameter("day")+"."+request.getParameter("month")+"."+request.getParameter("year");
							dataUser[3] = request.getParameter("city");
							dataUser[4] = request.getParameter("interests");
							dataUser[5] = request.getParameter("contact_information");
							dataUser[6] = request.getParameter("e-mail");
							dataUser[7] = request.getParameter("login");
							dataUser[8] = request.getParameter("password");
							dataUser[9] = request.getParameter("repassword");

							String[][] responseArray = Utils.toArrays(ws.registrate(Utils.toList(dataUser)));
							ArrayList<HashMap<String, ArrayList<String>>> answer = Parser.parse(responseArray);
                             
							if (!Boolean.parseBoolean(answer.get(0).get("errorhappend").get(0))) {
								int userId = -1;
                                                                
								userId = Integer.parseInt(answer.get(0).get("entityid").get(0));
								if (userId >= 0) {
									session.setAttribute("userid", userId);
									session.setAttribute("login",
											request.getParameter("login"));
					%><jsp:forward page="Welcome.jsp"></jsp:forward> <%
 	}
 		} else
 			out.println("<big><p align=\"center\" style=\"color:red;\">Error: "
 					+ answer.get(0).get("message").get(0)
 					+ "</p></big>");
 	}
 %>
					<form id="form2" name="form2" method="post"
						action="Registration.jsp">
						<table width="500" align="center">
							<tr>
								<td width="200px">
									<div align="right">
										<h3>* Имя:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<input type="text" name="firstname" />
									</div></td>
							</tr>
							<tr>
								<td width="200px">
									<div align="right">
										<h3>* Фамилия:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<input type="text" name="lastname" />
									</div></td>
							</tr>
							<tr>
								<td width="200px">
									<div align="right">
										<h3>* Дата рождения:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td>
									<div align="left">
										<label for="select"></label> <select name="day" id="select">
											<option value="0">Day</option>
											<%
												for (int i = 1; i <= 31; i++) {
											%>
											<option value="<%=i%>"><%=i%></option>
											<%
												}
											%>
										</select> <select name="month" id="select">
											<option value="0">Month</option>
											<%
												for (int i = 1; i <= 12; i++) {
											%>
											<option value="<%=i%>"><%=i%></option>
											<%
												}
											%>
										</select> <select name="year" id="select">
											<option value="0">Year</option>
											<%
												for (int i = 2012; i >= 1950; i--) {
											%>
											<option value="<%=i%>"><%=i%></option>
											<%
												}
											%>
										</select>
									</div>
								</td>
							</tr>
							<tr>
								<td width="200px">
									<div align="right">
										<h3>Родной город:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<input type="text" name="city" />
									</div></td>
							</tr>
							<tr>
								<td width="200px">
									<div align="right">
										<h3>Интересы:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<textarea rows="5" cols="25" name="interests"></textarea>
									</div></td>
							</tr>
							<tr>
								<td width="200px">
									<div align="right">
										<h3>Телефон:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<input type="text" value="+7" name="contact_information" />
									</div></td>
							</tr>
						</table>
						<div align="center">
							<em>Данные, введенные ниже, будут использоваться при входе
								пользователя в систему.</em>
						</div>
						<table width="500" align="center">
							<tr>
								<td width="200px">
									<div align="right">
										<h3>* Адрес e-mail:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<input type="text" name="e-mail" />
									</div></td>
							</tr>
							<tr>
								<td width="200px">
									<div align="right">
										<h3>* Логин:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<input type="text" name="login" />
									</div></td>
							</tr>
							<tr>
								<td width="200px">
									<div align="right">
										<h3>* Пароль:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<input type="password" name="password" />
									</div></td>
							</tr>
							<tr>
								<td width="200px">
									<div align="right">
										<h3>* Повторите пароль:</h3>
									</div>
								</td>
								<td width="50px"></td>
								<td><div align="left">
										<input type="password" name="repassword" />
									</div></td>
							</tr>
						</table>
						<div align="center">
							<input type="submit" name="registration" value="Регистрация" />
						</div>
					</form>
					<p>&nbsp;</p>
					<p>
						<a href="input.jsp">Вернуться на страницу авторизации</a>
					</p>
				</td>
			</tr>
		</table>
	</div>
</body>
</html>
